﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using nb.service;

public partial class sitemap : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GenerateProductMenuItem();
        }
    }

    void GenerateProductMenuItem()
    {
        rep_category.DataSource = new ProductCategoryService().getAllByLevel("1");
        rep_category.DataBind();
    }

    protected void rep_rep_category_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        string categoryID = "";
        ProductCategoryService pcs = new ProductCategoryService();
        //
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            categoryID = ((HiddenField)e.Item.FindControl("hid_parentCategoryid")).Value;
            if (!pcs.hasSubCategory(categoryID))
            {
                ((Literal)e.Item.FindControl("lit_partentCategory")).Text = "<a href='" + ResolveUrl("product/product.aspx?cid=" + categoryID + "") + "'>" + ((Literal)e.Item.FindControl("lit_partentCategory")).Text + "</a>";
            }
            else
            {
                ((Literal)e.Item.FindControl("lit_partentCategory")).Text = "<span style=\"padding-right:83px\">" + ((Literal)e.Item.FindControl("lit_partentCategory")).Text + "</span>";
                Repeater subCategory = (Repeater)e.Item.FindControl("rep_sub");
                subCategory.DataSource = pcs.getListByParent(categoryID);
                subCategory.DataBind();
            }
        }
    }
}